#include <vector>
using std::vector;

#include <utility>
using std::swap;

#include <iostream>
using std::cout;
using std::endl;

// 分析自己的核心思路
class Solution 
{
public:
	void moveZeroes(vector<int>& nums) 
	{
		int sign0 = 0;
		int sign1 = 0;
		int size = nums.size();
		
		while (sign0 < size && sign1 < size)
		{
			// 找到一个零
			while (nums[sign0] != 0 && sign0 < size)
			{
				++sign0;
			}
			
			// 找到下一个非零
			sign1 = sign0 + 1;
			while (nums[sign1] == 0 && sign1 < size)
			{
				++sign1;
			}
			// 交换
			if (sign0 < size && sign1 < size)
			{
				swap(nums[sign0], nums[sign1]);
			}
			
		}
		
	}
};

int main()
{
	vector<int> v1;
	v1.push_back(1);
	v1.push_back(0);
	v1.push_back(1);
	v1.push_back(1);
	v1.push_back(1);
	
	for (auto e : v1)
	{
		cout << e << " ";
	}
	cout << endl;
	
	Solution frist;
	frist.moveZeroes(v1);
	
	for (auto e : v1)
	{
		cout << e << " ";
	}
	cout << endl;
	
	return 0;
}
